package util;

import java.util.Random;

/**
 * Random number
 * @author tigerzhong
 *
 */
public class MyMath {
    /**
     * Generate random number
     * 
     * @param l
     * @param u
     * @return Random number in [l,u)
     */
    public static int generateRand(int l, int u) {
	long seed = (long) (Math.random() * 100000000L);
	Random rand = new Random();
	rand.setSeed(seed);
	return rand.nextInt(u - l) + l;
    }

    /**
     * Generate random number
     * 
     * @param l
     * @param u
     * @return Random number in [l,u)
     */
    public static double generateRand(double l, double u) {
	long seed = (long) (Math.random() * 100000000L);
	Random rand = new Random();
	rand.setSeed(seed);
	return rand.nextDouble() * (u - l);
    }

    /**
     * Get the index of maximal number
     * 
     * @param v, double value vector
     * @return index of maximal number
     */
    public static int getMaxIdx(double[] v) {
	double maxVal = Double.MIN_VALUE;
	int idx = -1;
	for (int i = 0; i < v.length; i++) {
	    if (v[i] > maxVal) {
		idx = i;
		maxVal = v[i];
	    }
	}
	return idx;
    }
}
